//
//  TJEmployeeManageCell.m
//  BaoDian
//
//  Created by mac on 2024/7/27.
//

#import "TJStaffManageCell.h"
#import "TJUserPublishDataView.h"


@interface TJStaffManageCell()

@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UILabel *stateLabel;
@property (nonatomic, weak) UILabel *validDateValueLabel;
@property (nonatomic, weak) UILabel *employeeNumberValueLabel;
@property (nonatomic, weak) TJUserPublishDataView *dataView;

@end

@implementation TJStaffManageCell

- (void)settingSubView {
    [super settingSubView];
    
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = UIColor.tj_backgroundColor;
    
    UIView *tj_contentView = [UIView addToView:self.contentView];
    tj_contentView.backgroundColor = UIColor.tj_1E1F23Color;
    tj_contentView.addCornerRadius(12);
    [tj_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.inset(16);
        make.top.offset(0);
    }];
    
    UIView *topView = [UIView addToView:tj_contentView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(0);
        make.top.offset(0);
        make.height.offset(44);
    }];
    
    UIImageView *iconImageView = [UIImageView addToView:topView];
    iconImageView.image = [UIImage imageNamed:@"groupIcon"];
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.centerY.offset(0);
        make.left.offset(16);
    }];
    
    UILabel *nameLabel = [UILabel lableWithSuperView:topView font:UIFontMake(16) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentCenter];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.equalTo(iconImageView.mas_right).offset(6);
    }];
    
    UILabel *stateLabel = [UILabel lableWithSuperView:topView font:UIFontMake(12) color:UIColorMake(0xEF382D) title:@"正常" textAlignment:NSTextAlignmentCenter];
    stateLabel.addCornerRadius(4);
    stateLabel.layer.borderWidth = 0.5;
    stateLabel.layer.borderColor = UIColorMake(0xEF382D).CGColor;
    [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.inset(16);
        make.width.offset(32);
        make.height.offset(18);
    }];

    UIView *lineView = [UIView addToView:topView];
    lineView.backgroundColor = UIColorMake(0x2A2B31);
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(16);
        make.height.offset(1);
        make.bottom.offset(0);
    }];
    
    UILabel *validDateLabel = [UILabel lableWithSuperView:topView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"有效日期" textAlignment:NSTextAlignmentLeft];
    [validDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom).offset(10);
        make.left.equalTo(iconImageView);
    }];
    
    UILabel *validDateValueLabel = [UILabel lableWithSuperView:topView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:nil textAlignment:NSTextAlignmentLeft];
    [validDateValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(validDateLabel);
        make.right.equalTo(lineView);
    }];
    
    UILabel *employeeNumberLabel = [UILabel lableWithSuperView:topView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"员工数" textAlignment:NSTextAlignmentLeft];
    [employeeNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(validDateLabel.mas_bottom).offset(8);
        make.left.equalTo(iconImageView);
    }];
    
    UILabel *employeeNumberValueLabel = [UILabel lableWithSuperView:topView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:nil textAlignment:NSTextAlignmentLeft];
    [employeeNumberValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(employeeNumberLabel);
        make.right.equalTo(lineView);
    }];
    
    TJUserPublishDataView *dataView = [TJUserPublishDataView addToView:tj_contentView];
    dataView.backgroundColor = UIColorMake(0x2A2B31);
    dataView.addCornerRadius(8);
    [dataView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(lineView);
        make.height.offset(52);
        make.top.equalTo(employeeNumberLabel.mas_bottom).offset(12);
    }];
    
    UIView *bottomView = [UIView addToView:tj_contentView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(0);
        make.bottom.offset(0);
        make.top.equalTo(dataView.mas_bottom);
    }];
    
    UIButton *deleteButton = [UIButton buttonWithSuperView:bottomView font:UIFontMake(12) color:UIColor.tj_8D9298Color title:@"删除"];
    deleteButton.addCornerRadius(14);
    deleteButton.layer.borderWidth = 0.5;
    deleteButton.layer.borderColor = UIColor.tj_8D9298Color.CGColor;
    [deleteButton addTarget:self action:@selector(didClickDeleteButton) forControlEvents:UIControlEventTouchUpInside];
    [deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.inset(16);
        make.width.offset(48);
        make.height.offset(28);
    }];
    
    UIButton *groupButton = [UIButton buttonWithSuperView:bottomView font:UIFontMake(12) color:UIColor.whiteColor title:@"查看分组"];
    groupButton.backgroundColor = UIColorMake(0x2978F0);
    groupButton.addCornerRadius(14);
    [groupButton addTarget:self action:@selector(didClickGroupButton) forControlEvents:UIControlEventTouchUpInside];
    [groupButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.inset(16);
        make.width.offset(72);
        make.height.offset(28);
    }];
    
    UIButton *changeNameButton = [UIButton buttonWithSuperView:bottomView font:UIFontMake(12) color:UIColorMake(0x2978F0) title:@"修改名称"];
    changeNameButton.addCornerRadius(4);
    changeNameButton.layer.borderWidth = 0.5;
    [changeNameButton addTarget:self action:@selector(didClickChangeNameButton) forControlEvents:UIControlEventTouchUpInside];
    changeNameButton.layer.borderColor = UIColorMake(0x2978F0).CGColor;
    changeNameButton.addCornerRadius(14);
    [changeNameButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.equalTo(groupButton.mas_left).inset(10);
        make.width.offset(72);
        make.height.offset(28);
    }];
    
    _nameLabel = nameLabel;
    _stateLabel = stateLabel;
    _validDateValueLabel = validDateValueLabel;
    _employeeNumberValueLabel = employeeNumberValueLabel;
    _dataView = dataView;
    
}

- (void)setModel:(TJStaffManageModel *)model {
    _model = model;
    
    
    _nameLabel.text = model.name;
    _validDateValueLabel.text = model.expireTime;
    _employeeNumberValueLabel.text = [NSString stringWithFormat:@"%d/%@", model.userTotal.intValue -  model.userRemaining.intValue, model.userTotal];
    _dataView.publishCountItem.textLabel.text = model.sendCount;
    _dataView.playerCountItem.textLabel.text = model.playCount;
    _dataView.likeCountItem.textLabel.text = model.diggCount;
    _dataView.commentCountItem.textLabel.text = model.commentCount;
    
    
    if (model.status.intValue == 0) {
        _stateLabel.layer.borderColor = UIColorMake(0x2978F0).CGColor;
        _stateLabel.textColor = UIColorMake(0x2978F0);
        _stateLabel.text = @"正常";

    } else if (model.status.intValue == 1) {
        _stateLabel.layer.borderColor = UIColorMake(0xEF382D).CGColor;
        _stateLabel.textColor = UIColorMake(0xEF382D);
        _stateLabel.text = @"过期";
    } else {
        _stateLabel.layer.borderColor = UIColorMake(0xEF382D).CGColor;
        _stateLabel.textColor = UIColorMake(0xEF382D);
        _stateLabel.text = @"禁用";
    }
}

- (void)didClickDeleteButton {
    if (_didClickDeleteButtonBlock) {
        _didClickDeleteButtonBlock();
    }
}

- (void)didClickGroupButton {
    if (_didClickGroupButtonBlock) {
        _didClickGroupButtonBlock();
    }
}

- (void)didClickChangeNameButton {
    if (_didClickChangeNameButtonBlock) {
        _didClickChangeNameButtonBlock();
    }
}

@end
